#include "Include.h"



const u8 PowerVad_Tab[4]= {C_AD_260V,C_AD_250V,C_AD_240V,C_AD_230V};   //260~230
const u16 TargetPower_LimitTab[4]={C_HIGHVOLTAGE_LIMITPOW_260V,C_HIGHVOLTAGE_LIMITPOW_250V,C_HIGHVOLTAGE_LIMITPOW_240V,C_HIGHVOLTAGE_LIMITPOW_230V};//功率值

/*******************************************************************************
** Name: Get_LimTargetPower
** Description: 功率計算前限制追功率所需的目標功率
** Input: 
** Ouput: 功率值
********************************************************************************/

u16 Get_LimTargetPower() ////limit the power	
{
    vu16 TargetPower_Temp = 0;	
    vu8 i=0,i_Copy=0;
	
	TargetPower=PowerStep*20;	
	
	TargetPower_Temp = TargetPower;
			
	//Overvoltage limiting power
	//高電壓限制最低功率,請根據實際項目需求更改
	for(i=0;i<=3;i++)  //需要和數組對應上
	{	
		//
		if(AD_Vac>=PowerVad_Tab[i])
		{	
			//>1000W
			if(TargetPower > POWER_STEP_MIN*20)	
			{				 				
				//連續功率檔位高於正常電壓時，限制最低功率
				i_Copy=i;
		
				if(TargetPower<=(TargetPower_LimitTab[i_Copy]) )   //限制功率，誰大用誰
				{		
					TargetPower_Temp=TargetPower_LimitTab[i_Copy];
				}			
				break;
			}
			else// <=1000W
			{
				//<600
				if(TargetPower<C_HIGHVOLTAGE_LIMITMINLOWPOW)
				{
					TargetPower_Temp = C_HIGHVOLTAGE_LIMITMINLOWPOW;
				}
			}
		}	
	}
	
	//IGBT Over temperature drop power
	if( (bIGBT_HTemp_PowDrop==1) && (TargetPower_Temp >= C_IGBT_HIGHTEMP_LIMITPOWER) )// 0:normal	1:igbt Over 90 degrees Celsius
    {
		TargetPower_Temp = C_IGBT_HIGHTEMP_LIMITPOWER; 	//1600W
    }
    return TargetPower_Temp;
}